using System;

namespace SG3L_RAG.Domain.Entities
{
    public class Permission : EntityBase
    {
        public Guid DocumentId { get; private set; }
        public Document? Document { get; private set; }
        public Guid UserId { get; private set; }
        public User? User { get; private set; }
        public string PermissionType { get; private set; } = string.Empty;

        // EF Core 需要的无参构造函数
        public Permission() { }

        // 业务构造函数
        private Permission(Guid documentId, Guid userId, string permissionType)
        {
            DocumentId = documentId;
            UserId = userId;
            PermissionType = permissionType;
        }

        // 工厂方法
        public static Permission Create(Guid documentId, Guid userId, string permissionType)
        {
            return new Permission(documentId, userId, permissionType);
        }

        public bool IsEditable() => PermissionType == "edit";
        public bool IsReadable() => PermissionType == "read";
        public bool IsPublic() => Document != null && Document.Permission == "public";

        // 授权方法
        public void ChangePermissionType(string newType)
        {
            PermissionType = newType;
        }
    }
}
